commit 5b3af430f2d71ee871b45e6dcc705141308f26d8
Author: root <root@srv-xen-moodle08.tauntons.ac.uk>
Date:   Mon Oct 26 14:08:08 2009 +0000

    Fixed bug with pre-DST change booking not showing up post-change

diff --git a/blocks/mrbs/web/day.php b/blocks/mrbs/web/day.php
index 63a2e3a..5b6626d 100644
--- a/blocks/mrbs/web/day.php
+++ b/blocks/mrbs/web/day.php
@@ -37,28 +37,28 @@ if (empty($debug_flag)) $debug_flag = 0;
 #If we dont know the right date then make it up
 if (($day==0) or ($month==0) or ($year==0))
 {
-	$day   = date("d");
-	$month = date("m");
-	$year  = date("Y");
+    $day   = date("d");
+    $month = date("m");
+    $year  = date("Y");
 } else {
 # Make the date valid if day is more then number of days in month
-	while (!checkdate(intval($month), intval($day), intval($year)))
-		$day--;
+    while (!checkdate(intval($month), intval($day), intval($year)))
+        $day--;
 }
 // if (($area>0))
-//	$area = get_default_area();
+//    $area = get_default_area();
 
 # print the page header
 print_header_mrbs($day, $month, $year, $area);
 
 $format = "Gi";
 if( $enable_periods ) {
-	$format = "i";
-	$resolution = 60;
-	$morningstarts = 12;
-	$morningstarts_minutes = 0;
-	$eveningends = 12;
-	$eveningends_minutes = count($periods)-1;
+    $format = "i";
+    $resolution = 60;
+    $morningstarts = 12;
+    $morningstarts_minutes = 0;
+    $eveningends = 12;
+    $eveningends_minutes = count($periods)-1;
 
 }
 
@@ -87,19 +87,19 @@ if ( $pview != 1 ) {
    # need to show either a select box or a normal html list,
    # depending on the settings in config.inc.php
    if ($area_list_format == "select") {
-	echo make_area_select_html('day.php', $area, $year, $month, $day); # from functions.php
+    echo make_area_select_html('day.php', $area, $year, $month, $day); # from functions.php
    } else {
-	# show the standard html list
-	$sql = "select id, area_name from $tbl_area order by area_name";
-   	$res = sql_query($sql);
-
-   	if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
-   	{
-		echo "<a href=\"day.php?year=$year&month=$month&day=$day&area=$row[0]\">";
-		if ($row[0] == $area)
-			echo "<font color=\"red\">" . htmlspecialchars($row[1]) . "</font></a><br>\n";
-		else echo htmlspecialchars($row[1]) . "</a><br>\n";
-   	}
+    # show the standard html list
+    $sql = "select id, area_name from $tbl_area order by area_name";
+       $res = sql_query($sql);
+
+       if ($res) for ($i = 0; ($row = sql_row($res, $i)); $i++)
+       {
+        echo "<a href=\"day.php?year=$year&month=$month&day=$day&area=$row[0]\">";
+        if ($row[0] == $area)
+            echo "<font color=\"red\">" . htmlspecialchars($row[1]) . "</font></a><br>\n";
+        else echo htmlspecialchars($row[1]) . "</a><br>\n";
+       }
    }
    echo "</td>\n";
 
@@ -151,90 +151,102 @@ if ($area <= 0) {
 
 
 if (!empty($area)) {
-    $sql = "SELECT $tbl_room.id, start_time, end_time, name, $tbl_entry.id, type,
-            $tbl_entry.description
-            FROM $tbl_entry, $tbl_room
-            WHERE $tbl_entry.room_id = $tbl_room.id
-            AND area_id = $area
+    $booking_sql = "SELECT e.id AS id, r.id AS roomid, start_time, end_time, name, type,
+            e.description AS description
+            FROM ".$CFG->prefix."mrbs_entry AS e
+                JOIN ".$CFG->prefix."mrbs_room AS r ON e.room_id = r.id
+            WHERE area_id = $area
             AND start_time <= $pm7 AND end_time > $am7";
 
-    $res = sql_query($sql);
-    if (!$res) fatal_error(0, sql_error());
-    for ($i = 0; ($row = sql_row($res, $i)); $i++) { //Each row we have is an appointment.
-
-        #Row[0] = Room ID
-	    #row[1] = start time
-	    #row[2] = end time
-	    #row[3] = short description
-	    #row[4] = id of this booking
-	    #row[5] = type (internal/external)
-	    #row[6] = description
-
-    	# $today is a map of the screen that will be displayed
-	    # It looks like:
-	    #     $today[Room ID][Time][id]
-	    #                          [color]
-	    #                          [data]
-	    #                          [long_descr]
-
-	    # Fill in the map for this meeting. Start at the meeting start time,
-	   # or the day start time, whichever is later. End one slot before the
-	   # meeting end time (since the next slot is for meetings which start then),
-	   # or at the last slot in the day, whichever is earlier.
-	   # Time is of the format HHMM without leading zeros.
-	   #
-	   # Note: int casts on database rows for max may be needed for PHP3.
-	   # Adjust the starting and ending times so that bookings which don't
-	   # start or end at a recognized time still appear.
-
-	   $start_t = max(round_t_down($row[1], $resolution, $am7), $am7);
-	   $end_t = min(round_t_up($row[2], $resolution, $am7) - $resolution, $pm7);
-	   for ($t = $start_t; $t <= $end_t; $t += $resolution)
-	   {
+    if(!$bookings = get_records_sql($booking_sql)) {
+        $bookings = array();
+    }
+
+    $dst_booking_sql = "SELECT e.id AS id, r.id AS roomid, start_time, end_time, name, type,
+            e.description AS description, timestamp
+            FROM ".$CFG->prefix."mrbs_entry AS e
+                JOIN ".$CFG->prefix."mrbs_room AS r ON e.room_id = r.id
+            WHERE area_id = $area
+            AND start_time <= ".mrbs_uncorrect_dst($pm7)." AND end_time > ".mrbs_uncorrect_dst($am7);
+
+    if(!$dst_bookings = get_records_sql($dst_booking_sql)) {
+        $dst_bookings = array();
+    }
+    foreach ($dst_bookings as $key => $dst_booking) {
+        if($dst_booking->start_time != mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time)) {
+            $dst_booking->start_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time);
+            $dst_booking->end_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->end_time);
+            $bookings[$key] = $dst_booking;
+        }
+    }
+
+    foreach($bookings as $booking) { //Each row we have is an appointment.
+
+        # $today is a map of the screen that will be displayed
+        # It looks like:
+        #     $today[Room ID][Time][id]
+        #                          [color]
+        #                          [data]
+        #                          [long_descr]
+
+        # Fill in the map for this meeting. Start at the meeting start time,
+       # or the day start time, whichever is later. End one slot before the
+       # meeting end time (since the next slot is for meetings which start then),
+       # or at the last slot in the day, whichever is earlier.
+       # Time is of the format HHMM without leading zeros.
+       #
+       # Note: int casts on database rows for max may be needed for PHP3.
+       # Adjust the starting and ending times so that bookings which don't
+       # start or end at a recognized time still appear.
+
+       $start_t = max(round_t_down($booking->start_time, $resolution, $am7), $am7);
+       $end_t = min(round_t_up($booking->end_time, $resolution, $am7) - $resolution, $pm7);
+       for ($t = $start_t; $t <= $end_t; $t += $resolution)
+       {
           //checks for double bookings
-          if(empty($today[$row[0]][date($format,$t)])){
+          if(empty($today[$booking->roomid][date($format,$t)])){
 
-		  $today[$row[0]][date($format,$t)]["id"]    = $row[4];
-		  $today[$row[0]][date($format,$t)]["color"] = $row[5];
-              $today[$row[0]][date($format,$t)]["data"]  .= "";
-              $today[$row[0]][date($format,$t)]["long_descr"]  .= "";
-              $today[$row[0]][date($format,$t)]["double_booked"]  = false;
+          $today[$booking->roomid][date($format,$t)]["id"]    = $booking->id;
+          $today[$booking->roomid][date($format,$t)]["color"] = $booking->type;
+              $today[$booking->roomid][date($format,$t)]["data"]  .= "";
+              $today[$booking->roomid][date($format,$t)]["long_descr"]  .= "";
+              $today[$booking->roomid][date($format,$t)]["double_booked"]  = false;
           }else{
-              $today[$row[0]][date($format,$t)]["id"]    .= ','.$row[4];
-              $today[$row[0]][date($format,$t)]["data"]  .= "\n";
-              $today[$row[0]][date($format,$t)]["long_descr"]  .= ",";
-              $today[$row[0]][date($format,$t)]["double_booked"]  = true;
+              $today[$booking->roomid][date($format,$t)]["id"]    .= ','.$booking->id;
+              $today[$booking->roomid][date($format,$t)]["data"]  .= "\n";
+              $today[$booking->roomid][date($format,$t)]["long_descr"]  .= ",";
+              $today[$booking->roomid][date($format,$t)]["double_booked"]  = true;
           }
-	   }
-
-	   # Show the name of the booker in the first segment that the booking
-	   # happens in, or at the start of the day if it started before today.
-	   if ($row[1] < $am7)
-	   {
-		  $today[$row[0]][date($format,$am7)]["data"] .= $row[3];
-		  $today[$row[0]][date($format,$am7)]["long_descr"] .= $row[6];
-	   }
-	   else
-	   {
-		  $today[$row[0]][date($format,$start_t)]["data"] .= $row[3];
-		  $today[$row[0]][date($format,$start_t)]["long_descr"] .= $row[6];
-	   }
+       }
+
+       # Show the name of the booker in the first segment that the booking
+       # happens in, or at the start of the day if it started before today.
+       if ($booking->start_time < $am7)
+       {
+          $today[$booking->roomid][date($format,$am7)]["data"] .= $booking->name;
+          $today[$booking->roomid][date($format,$am7)]["long_descr"] .= $booking->description;
+       }
+       else
+       {
+          $today[$booking->roomid][date($format,$start_t)]["data"] .= $booking->name;
+          $today[$booking->roomid][date($format,$start_t)]["long_descr"] .= $booking->description;
+       }
     }
 
 
     if ($debug_flag)
     {
-	   echo "<p>DEBUG:<pre>\n";
-	   echo "\$dst_change = $dst_change\n";
-	   echo "\$am7 = $am7 or " . date($format,$am7) . "\n";
-	   echo "\$pm7 = $pm7 or " . date($format,$pm7) . "\n";
-	   if (gettype($today) == "array")
-	   while (list($w_k, $w_v) = each($today))
-		  while (list($t_k, $t_v) = each($w_v))
-			 while (list($k_k, $k_v) = each($t_v))
-			 	echo "d[$w_k][$t_k][$k_k] = '$k_v'\n";
-	   else echo "today is not an array!\n";
-	   echo "</pre><p>\n";
+       echo "<p>DEBUG:<pre>\n";
+       echo "\$dst_change = $dst_change\n";
+       echo "\$am7 = $am7 or " . date($format,$am7) . "\n";
+       echo "\$pm7 = $pm7 or " . date($format,$pm7) . "\n";
+       if (gettype($today) == "array")
+       while (list($w_k, $w_v) = each($today))
+          while (list($t_k, $t_v) = each($w_v))
+             while (list($k_k, $k_v) = each($t_v))
+                 echo "d[$w_k][$t_k][$k_k] = '$k_v'\n";
+       else echo "today is not an array!\n";
+       echo "</pre><p>\n";
     }
 
     # We need to know what all the rooms area called, so we can show them all
@@ -251,26 +263,26 @@ if (!empty($area)) {
     if (! $res) fatal_error(0, sql_error());
     if (sql_count($res) == 0)
     {
-	   echo "<h1>".get_string('no_rooms_for_area','block_mrbs')."</h1>";
-	   sql_free($res);
+       echo "<h1>".get_string('no_rooms_for_area','block_mrbs')."</h1>";
+       sql_free($res);
     }
     else
     {
-	   #Show current date
-	   echo "<h2 align=center>" . userdate($am7, "%A %d %B %Y") . "</h2>\n";
+       #Show current date
+       echo "<h2 align=center>" . userdate($am7, "%A %d %B %Y") . "</h2>\n";
 
-	   if ( $pview != 1 ) {
-		  #Show Go to day before and after links
+       if ( $pview != 1 ) {
+          #Show Go to day before and after links
             $output = "<table width=\"100%\"><tr><td><a href=\"day.php?year=$yy&month=$ym&day=$yd&area=$area\">&lt;&lt;".get_string('daybefore','block_mrbs')."</a></td>
             <td align=center><a href=\"day.php?area=$area\">".get_string('gototoday','block_mrbs')."</a></td>
             <td align=right><a href=\"day.php?year=$ty&month=$tm&day=$td&area=$area\">".get_string('dayafter','block_mrbs')."&gt;&gt;</a></td></tr></table>\n";
             print $output;
-	   }
+       }
 
-    	// Include the active cell content management routines.
-	   // Must be included before the beginnning of the main table.
-	   if ($javascript_cursor) { // If authorized in config.inc.php, include the javascript cursor management.
-	       echo "<SCRIPT language=\"JavaScript\" type=\"text/javascript\" src=\"xbLib.js\"></SCRIPT>\n";
+        // Include the active cell content management routines.
+       // Must be included before the beginnning of the main table.
+       if ($javascript_cursor) { // If authorized in config.inc.php, include the javascript cursor management.
+           echo "<SCRIPT language=\"JavaScript\" type=\"text/javascript\" src=\"xbLib.js\"></SCRIPT>\n";
            echo "<SCRIPT language=\"JavaScript\">InitActiveCell("
                 . ($show_plus_link ? "true" : "false") . ", "
                 . "true, "
@@ -280,19 +292,19 @@ if (!empty($area)) {
                 . ");</SCRIPT>\n";
        }
 
-	   #This is where we start displaying stuff
-	   echo "<table cellspacing=0 border=1 width=\"100%\">";
-	   echo "<tr><th width=\"1%\">".($enable_periods ? get_string('period','block_mrbs') : get_string('time'))."</th>";
+       #This is where we start displaying stuff
+       echo "<table cellspacing=0 border=1 width=\"100%\">";
+       echo "<tr><th width=\"1%\">".($enable_periods ? get_string('period','block_mrbs') : get_string('time'))."</th>";
 
         $room_column_width = (int)(95 / sql_count($res));
-	   for ($i = 0; ($row = sql_row($res, $i)); $i++) {
+       for ($i = 0; ($row = sql_row($res, $i)); $i++) {
             echo "<th width=\"$room_column_width%\">
             <a href=\"week.php?year=$year&month=$month&day=$day&area=$area&room=$row[2]\"
             title=\"" . get_string('viewweek','block_mrbs') . " &#10;&#10;$row[3]\">"
             . htmlspecialchars($row[0]) . ($row[1] > 0 ? "($row[1])" : "") . "
             <br />$row[3]</a></th>";//print the room description as well
-		    $rooms[] = $row[2];
-	   }
+            $rooms[] = $row[2];
+       }
 
         # next line to display times on right side
         if ( FALSE != $times_right_side )
@@ -302,97 +314,97 @@ if (!empty($area)) {
         }
         echo "</tr>\n";
 
-	   # URL for highlighting a time. Don't use REQUEST_URI or you will get
-	   # the timetohighlight parameter duplicated each time you click.
-	   $hilite_url="day.php?year=$year&month=$month&day=$day&area=$area&timetohighlight";
-
-	   # This is the main bit of the display
-	   # We loop through time and then the rooms we just got
-
-	   # if the today is a day which includes a DST change then use
-	   # the day after to generate timesteps through the day as this
-	   # will ensure a constant time step
-	   ( $dst_change != -1 ) ? $j = 1 : $j = 0;
-
-	   $row_class = "even_row";
-	   for (
-		  $t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day+$j, $year);
-		  $t <= mktime($eveningends, $eveningends_minutes, 0, $month, $day+$j, $year);
-		  $t += $resolution, $row_class = ($row_class == "even_row")?"odd_row":"even_row"
-	   )
-	   {
-		  # convert timestamps to HHMM format without leading zeros
-		  $time_t = date($format, $t);
-
-		  # Show the time linked to the URL for highlighting that time
-		  echo "<tr>";
-		  tdcell("red");
-		  if( $enable_periods ){
-			 $time_t_stripped = preg_replace( "/^0/", "", $time_t );
-			 echo "<a href=\"$hilite_url=$time_t\"  title=\""
+       # URL for highlighting a time. Don't use REQUEST_URI or you will get
+       # the timetohighlight parameter duplicated each time you click.
+       $hilite_url="day.php?year=$year&month=$month&day=$day&area=$area&timetohighlight";
+
+       # This is the main bit of the display
+       # We loop through time and then the rooms we just got
+
+       # if the today is a day which includes a DST change then use
+       # the day after to generate timesteps through the day as this
+       # will ensure a constant time step
+       ( $dst_change != -1 ) ? $j = 1 : $j = 0;
+
+       $row_class = "even_row";
+       for (
+          $t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day+$j, $year);
+          $t <= mktime($eveningends, $eveningends_minutes, 0, $month, $day+$j, $year);
+          $t += $resolution, $row_class = ($row_class == "even_row")?"odd_row":"even_row"
+       )
+       {
+          # convert timestamps to HHMM format without leading zeros
+          $time_t = date($format, $t);
+
+          # Show the time linked to the URL for highlighting that time
+          echo "<tr>";
+          tdcell("red");
+          if( $enable_periods ){
+             $time_t_stripped = preg_replace( "/^0/", "", $time_t );
+             echo "<a href=\"$hilite_url=$time_t\"  title=\""
              . get_string('highlight_line','block_mrbs') . "\">"
              . $periods[$time_t_stripped] . "</a></td>\n";
-		  } else {
-			echo "<a href=\"$hilite_url=$time_t\" title=\""
+          } else {
+            echo "<a href=\"$hilite_url=$time_t\" title=\""
             . get_string('highlight_line','block_mrbs') . "\">"
             . userdate($t,hour_min_format()) . "</a></td>\n";
-		  }
-
-		# Loop through the list of rooms we have for this area
-		while (list($key, $room) = each($rooms))
-		{
-			if(isset($today[$room][$time_t]["id"]))
-			{
-				$id    = $today[$room][$time_t]["id"];
-				$color = $today[$room][$time_t]["color"];
-				$descr = htmlspecialchars($today[$room][$time_t]["data"]);
-				$long_descr = htmlspecialchars($today[$room][$time_t]["long_descr"]);
+          }
+
+        # Loop through the list of rooms we have for this area
+        while (list($key, $room) = each($rooms))
+        {
+            if(isset($today[$room][$time_t]["id"]))
+            {
+                $id    = $today[$room][$time_t]["id"];
+                $color = $today[$room][$time_t]["color"];
+                $descr = htmlspecialchars($today[$room][$time_t]["data"]);
+                $long_descr = htmlspecialchars($today[$room][$time_t]["long_descr"]);
                 $double_booked = $today[$room][$time_t]["double_booked"];
                 if($double_booked) $color='DoubleBooked';
-			}
-			else
-				unset($id);
-
-			# $c is the colour of the cell that the browser sees. White normally,
-			# red if were hightlighting that line and a nice attractive green if the room is booked.
-			# We tell if its booked by $id having something in it
-			if (isset($id))
-				$c = $color;
-			elseif (($timetohighlight>0) && ($time_t == $timetohighlight))
-				$c = "red";
-			else
-				$c = $row_class; # Use the default color class for the row.
-
-			tdcell($c);
-
-			# If the room isnt booked then allow it to be booked
-			if(!isset($id))
-			{
-				$hour = date("H",$t);
-				$minute  = date("i",$t);
-
-				if ( $pview != 1 ) {
-					if ($javascript_cursor)
-					{
-						echo "<SCRIPT language=\"JavaScript\">\n<!--\n";
-						echo "BeginActiveCell();\n";
-						echo "// -->\n</SCRIPT>";
-					}
-					echo "<center>";
-					if( $enable_periods ) {
-						echo "<a href=\"edit_entry.php?area=$area&room=$room&period=$time_t_stripped&year=$year&month=$month&day=$day\"><img src=new.gif width=10 height=10 border=0></a>";
-					} else {
-						echo "<a href=\"edit_entry.php?area=$area&room=$room&hour=$hour&minute=$minute&year=$year&month=$month&day=$day\"><img src=new.gif width=10 height=10 border=0></a>";
-					}
-					echo "</center>";
-					if ($javascript_cursor)
-					{
-						echo "<SCRIPT language=\"JavaScript\">\n<!--\n";
-						echo "EndActiveCell();\n";
-						echo "// -->\n</SCRIPT>";
-					}
-				} else echo '&nbsp;';
-			}
+            }
+            else
+                unset($id);
+
+            # $c is the colour of the cell that the browser sees. White normally,
+            # red if were hightlighting that line and a nice attractive green if the room is booked.
+            # We tell if its booked by $id having something in it
+            if (isset($id))
+                $c = $color;
+            elseif (($timetohighlight>0) && ($time_t == $timetohighlight))
+                $c = "red";
+            else
+                $c = $row_class; # Use the default color class for the row.
+
+            tdcell($c);
+
+            # If the room isnt booked then allow it to be booked
+            if(!isset($id))
+            {
+                $hour = date("H",$t);
+                $minute  = date("i",$t);
+
+                if ( $pview != 1 ) {
+                    if ($javascript_cursor)
+                    {
+                        echo "<SCRIPT language=\"JavaScript\">\n<!--\n";
+                        echo "BeginActiveCell();\n";
+                        echo "// -->\n</SCRIPT>";
+                    }
+                    echo "<center>";
+                    if( $enable_periods ) {
+                        echo "<a href=\"edit_entry.php?area=$area&room=$room&period=$time_t_stripped&year=$year&month=$month&day=$day\"><img src=new.gif width=10 height=10 border=0></a>";
+                    } else {
+                        echo "<a href=\"edit_entry.php?area=$area&room=$room&hour=$hour&minute=$minute&year=$year&month=$month&day=$day\"><img src=new.gif width=10 height=10 border=0></a>";
+                    }
+                    echo "</center>";
+                    if ($javascript_cursor)
+                    {
+                        echo "<SCRIPT language=\"JavaScript\">\n<!--\n";
+                        echo "EndActiveCell();\n";
+                        echo "// -->\n</SCRIPT>";
+                    }
+                } else echo '&nbsp;';
+            }
             elseif ($double_booked){
                 $descrs=split("\n",$descr);
                 $long_descrs=split(",",$long_descr);
@@ -404,19 +416,19 @@ if (!empty($area)) {
             }
             for($i=0;$i<count($descrs);$i++){
                 if ($descrs[$i] != "")
-			{
-				#if it is booked then show
+            {
+                #if it is booked then show
                 echo " <a href=\"view_entry.php?id=$ids[$i]&area=$area&day=$day&month=$month&year=$year\" title=\"$long_descrs[$i]\">$descrs[$i]</a><br>";
-			}
-			else
+            }
+            else
                     echo "<a href=\"view_entry.php?id=$ids[$i]&area=$area&day=$day&month=$month&year=$year\" title=\"$long_descrs[$i]\">&nbsp;\"&nbsp;</a><br>";
             }
             unset($descrs);
             unset($long_descrs);
             unset($ids);
 
-			echo "</td>\n";
-		}
+            echo "</td>\n";
+        }
         # next lines to display times on right side
         if ( FALSE != $times_right_side )
         {
@@ -431,16 +443,16 @@ if (!empty($area)) {
             else
             {
                 tdcell("red");
-		        echo "<a href=\"$hilite_url=$time_t\" title=\""
+                echo "<a href=\"$hilite_url=$time_t\" title=\""
                 . get_string('highlight_line','block_mrbs') . "\">"
                 . userdate($t,hour_min_format()) . "</a></td>\n";
 
             }
         }
 
-		echo "</tr>\n";
-		reset($rooms);
-	}
+        echo "</tr>\n";
+        reset($rooms);
+    }
 }
 echo "</table>\n";
 (isset($output)) ? print $output : '';
diff --git a/blocks/mrbs/web/functions.php b/blocks/mrbs/web/functions.php
index 194e877..eb3a5f7 100644
--- a/blocks/mrbs/web/functions.php
+++ b/blocks/mrbs/web/functions.php
@@ -1389,7 +1389,7 @@ function to_hr_time($time){
 }
 
 /**
- * Check if a the time is in DST when the current time is not, or vice versa,
+ * Check if a the time passed is in DST when the current time is not, or vice versa,
  * and make appropriate corrections to ensure it shows up when being viewed booked or
  * viewed in the other timezone.
  *
@@ -1398,7 +1398,6 @@ function to_hr_time($time){
  */
 function mrbs_correct_dst($time) {
 	if(date('I', time()) == 1 && date('I', $time) == 0) {
-        // if we're making a booking rather than viewing one, reverse the change.
             $time = $time-3600;
 	} else if (date('I', time()) == 0 && date('I', $time) == 1) {
             $time = $time+3600;
@@ -1406,4 +1405,38 @@ function mrbs_correct_dst($time) {
     return $time;
 }
 
+/**
+ * Check if the time passed is in DST when the current time is too, or vice versa,
+ * and make corrections to allow us to look for bookings that had mrbs_correct_dst applied
+ * to them.
+ *
+ * @param int $time     Unix timestamp
+ *
+ */
+function mrbs_uncorrect_dst($time) {
+    if(date('I', time()) == 0 && date('I', $time) == 0) {
+            $time = $time-3600;
+    } else if (date('I', time()) == 1 && date('I', $time) == 1) {
+            $time = $time+3600;
+    }
+    return $time;
+}
+
+/**
+ * Check if the passed timestamp is in DST when the passed time is not, or vice versa,
+ * and make the appropriate correction to allow bookings found using mrbs_uncorrect_dst to
+ * be displayed alongside regular bookings.
+ *
+ * @param int $time     Unix timestamp
+ *
+ */
+function mrbs_correct_nodst($timestamp, $time) {
+    if(date('I', $timestamp) == 1 && date('I', $time) == 0) {
+            $time = $time+3600;
+    } else if (date('I', $timestamp) == 0 && date('I', $time) == 1) {
+            $time = $time-3600;
+    }
+    return $time;
+}
+
 ?>
diff --git a/blocks/mrbs/web/month.php b/blocks/mrbs/web/month.php
index 4bce3ce..b470531 100644
--- a/blocks/mrbs/web/month.php
+++ b/blocks/mrbs/web/month.php
@@ -61,29 +61,29 @@ $days_in_month = date("t", $month_start);
 $month_end = mktime(23, 59, 59, $month, $days_in_month, $year);
 
 if( $enable_periods ) {
-	$resolution = 60;
-	$morningstarts = 12;
-	$eveningends = 12;
-	$eveningends_minutes = count($periods)-1;
+    $resolution = 60;
+    $morningstarts = 12;
+    $eveningends = 12;
+    $eveningends_minutes = count($periods)-1;
 }
 
 
 # Define the start and end of each day of the month in a way which is not
 # affected by daylight saving...
 for ($j = 1; $j<=$days_in_month; $j++) {
-	# are we entering or leaving daylight saving
-	# dst_change:
-	# -1 => no change
-	#  0 => entering DST
-	#  1 => leaving DST
-	$dst_change[$j] = is_dst($month,$j,$year);
+    # are we entering or leaving daylight saving
+    # dst_change:
+    # -1 => no change
+    #  0 => entering DST
+    #  1 => leaving DST
+    $dst_change[$j] = is_dst($month,$j,$year);
         if(empty( $enable_periods )){
-		$midnight[$j]=mktime(0,0,0,$month,$j,$year, is_dst($month,$j,$year, 0));
-		$midnight_tonight[$j]=mktime(23,59,59,$month,$j,$year, is_dst($month,$j,$year, 23));
-	}
+        $midnight[$j]=mktime(0,0,0,$month,$j,$year, is_dst($month,$j,$year, 0));
+        $midnight_tonight[$j]=mktime(23,59,59,$month,$j,$year, is_dst($month,$j,$year, 23));
+    }
         else {
-		$midnight[$j]=mktime(12,0,0,$month,$j,$year, is_dst($month,$j,$year, 0));
-		$midnight_tonight[$j]=mktime(12,count($periods),59,$month,$j,$year, is_dst($month,$j,$year, 23));
+        $midnight[$j]=mktime(12,0,0,$month,$j,$year, is_dst($month,$j,$year, 0));
+        $midnight_tonight[$j]=mktime(12,count($periods),59,$month,$j,$year, is_dst($month,$j,$year, 23));
         }
 
     $midnight[$j] = mrbs_correct_dst($midnight[$j]);
@@ -201,27 +201,45 @@ $all_day = ereg_replace(" ", "&nbsp;", get_string('all_day','block_mrbs'));
 # row[2] = Entry ID
 # This data will be retrieved day-by-day fo the whole month
 for ($day_num = 1; $day_num<=$days_in_month; $day_num++) {
-	$sql = "SELECT start_time, end_time, id, name
-	   FROM $tbl_entry
-	   WHERE room_id=$room
-	   AND start_time <= $midnight_tonight[$day_num] AND end_time > $midnight[$day_num]
-	   ORDER by 1";
-
-	# Build an array of information about each day in the month.
-	# The information is stored as:
-	#  d[monthday]["id"][] = ID of each entry, for linking.
-	#  d[monthday]["data"][] = "start-stop" times or "name" of each entry.
-
-	$res = sql_query($sql);
-	if (! $res) echo sql_error();
-	else for ($i = 0; ($row = sql_row($res, $i)); $i++)
-	{
-	    if ($debug_flag)
-        	echo "<br>DEBUG: result $i, id $row[2], starts $row[0], ends $row[1]\n";
-
-            if ($debug_flag) echo "<br>DEBUG: Entry $row[2] day $day_num\n";
-            $d[$day_num]["id"][] = $row[2];
-            $d[$day_num]["shortdescrip"][] = $row[3];
+
+    $booking_sql = "SELECT id, start_time, end_time, name
+       FROM ".$CFG->prefix."mrbs_entry
+       WHERE room_id = $room
+       AND start_time <= $midnight_tonight[$day_num] AND end_time > $midnight[$day_num]
+       ORDER by 1";
+
+    if(!$bookings = get_records_sql($booking_sql)) {
+        $bookings = array();
+    }
+
+    $dst_booking_sql = "SELECT start_time, end_time, id, name, timestamp
+       FROM ".$CFG->prefix."mrbs_entry
+       WHERE room_id = $room
+       AND start_time <= ".mrbs_uncorrect_dst($midnight_tonight[$day_num])." AND end_time > ".mrbs_uncorrect_dst($midnight[$day_num])."
+       ORDER by 1";
+    if(!$dst_bookings = get_records_sql($dst_booking_sql)) {
+        $dst_bookings = array();
+    }
+    foreach ($dst_bookings as $key => $dst_booking) {
+        if($dst_booking->start_time != mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time)) {
+            $dst_booking->start_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time);
+            $dst_booking->end_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->end_time);
+            $bookings[$key] = $dst_booking;
+        }
+    }
+
+    # Build an array of information about each day in the month.
+    # The information is stored as:
+    #  d[monthday]["id"][] = ID of each entry, for linking.
+    #  d[monthday]["data"][] = "start-stop" times or "name" of each entry.
+
+    foreach ($bookings as $booking) {
+        if ($debug_flag)
+            echo "<br>DEBUG: result $i, id $booking->id, starts $booking->start_time, ends $booking->end_time\n";
+
+            if ($debug_flag) echo "<br>DEBUG: Entry $booking->id day $day_num\n";
+            $d[$day_num]["id"][] = $booking->id;
+            $d[$day_num]["shortdescrip"][] = $booking->name;
 
             # Describe the start and end time, accounting for "all day"
             # and for entries starting before/ending after today.
@@ -231,70 +249,70 @@ for ($day_num = 1; $day_num<=$days_in_month; $day_num++) {
             # will incorrectly line break after a -.
 
             if(empty( $enable_periods ) ){
-              switch (cmp3($row[0], $midnight[$day_num]) . cmp3($row[1], $midnight_tonight[$day_num] + 1))
+              switch (cmp3($booking->start_time, $midnight[$day_num]) . cmp3($booking->end_time, $midnight_tonight[$day_num] + 1))
               {
-        	case "> < ":         # Starts after midnight, ends before midnight
-        	case "= < ":         # Starts at midnight, ends before midnight
-                    $d[$day_num]["data"][] = userdate($row[0], hour_min_format()) . "~" . userdate($row[1], hour_min_format());
+            case "> < ":         # Starts after midnight, ends before midnight
+            case "= < ":         # Starts at midnight, ends before midnight
+                    $d[$day_num]["data"][] = userdate($booking->start_time, hour_min_format()) . "~" . userdate($booking->end_time, hour_min_format());
                     break;
-        	case "> = ":         # Starts after midnight, ends at midnight
-                    $d[$day_num]["data"][] = userdate($row[0], hour_min_format()) . "~24:00";
+            case "> = ":         # Starts after midnight, ends at midnight
+                    $d[$day_num]["data"][] = userdate($booking->start_time, hour_min_format()) . "~24:00";
                     break;
-        	case "> > ":         # Starts after midnight, continues tomorrow
-                    $d[$day_num]["data"][] = userdate($row[0], hour_min_format()) . "~====>";
+            case "> > ":         # Starts after midnight, continues tomorrow
+                    $d[$day_num]["data"][] = userdate($booking->start_time, hour_min_format()) . "~====>";
                     break;
-        	case "= = ":         # Starts at midnight, ends at midnight
+            case "= = ":         # Starts at midnight, ends at midnight
                     $d[$day_num]["data"][] = $all_day;
                     break;
-        	case "= > ":         # Starts at midnight, continues tomorrow
+            case "= > ":         # Starts at midnight, continues tomorrow
                     $d[$day_num]["data"][] = $all_day . "====>";
                     break;
-        	case "< < ":         # Starts before today, ends before midnight
-                    $d[$day_num]["data"][] = "<====~" . userdate($row[1], hour_min_format());
+            case "< < ":         # Starts before today, ends before midnight
+                    $d[$day_num]["data"][] = "<====~" . userdate($booking->end_time, hour_min_format());
                     break;
-        	case "< = ":         # Starts before today, ends at midnight
+            case "< = ":         # Starts before today, ends at midnight
                     $d[$day_num]["data"][] = "<====" . $all_day;
                     break;
-        	case "< > ":         # Starts before today, continues tomorrow
+            case "< > ":         # Starts before today, continues tomorrow
                     $d[$day_num]["data"][] = "<====" . $all_day . "====>";
                     break;
               }
-	    }
+        }
             else
             {
-              $start_str = ereg_replace(" ", "&nbsp;", period_time_string($row[0]));
-              $end_str   = ereg_replace(" ", "&nbsp;", period_time_string($row[1], -1));
-              switch (cmp3($row[0], $midnight[$day_num]) . cmp3($row[1], $midnight_tonight[$day_num] + 1))
+              $start_str = period_time_string($booking->start_time);
+              $end_str   = period_time_string($booking->end_time, -1);
+              switch (cmp3($booking->start_time, $midnight[$day_num]) . cmp3($booking->end_time, $midnight_tonight[$day_num] + 1))
               {
-        	case "> < ":         # Starts after midnight, ends before midnight
-        	case "= < ":         # Starts at midnight, ends before midnight
-                    $d[$day_num]["data"][] = $start_str . "~" . $end_str;
+            case "> < ":         # Starts after midnight, ends before midnight
+            case "= < ":         # Starts at midnight, ends before midnight
+                    $d[$day_num]["data"][] = $start_str . " - " . $end_str;
                     break;
-        	case "> = ":         # Starts after midnight, ends at midnight
+            case "> = ":         # Starts after midnight, ends at midnight
                     $d[$day_num]["data"][] = $start_str . "~24:00";
                     break;
-        	case "> > ":         # Starts after midnight, continues tomorrow
+            case "> > ":         # Starts after midnight, continues tomorrow
                     $d[$day_num]["data"][] = $start_str . "~====>";
                     break;
-        	case "= = ":         # Starts at midnight, ends at midnight
+            case "= = ":         # Starts at midnight, ends at midnight
                     $d[$day_num]["data"][] = $all_day;
                     break;
-        	case "= > ":         # Starts at midnight, continues tomorrow
+            case "= > ":         # Starts at midnight, continues tomorrow
                     $d[$day_num]["data"][] = $all_day . "====>";
                     break;
-        	case "< < ":         # Starts before today, ends before midnight
+            case "< < ":         # Starts before today, ends before midnight
                     $d[$day_num]["data"][] = "<====~" . $end_str;
                     break;
-        	case "< = ":         # Starts before today, ends at midnight
+            case "< = ":         # Starts before today, ends at midnight
                     $d[$day_num]["data"][] = "<====" . $all_day;
                     break;
-        	case "< > ":         # Starts before today, continues tomorrow
+            case "< > ":         # Starts before today, continues tomorrow
                     $d[$day_num]["data"][] = "<====" . $all_day . "====>";
                     break;
               }
             }
 
-	}
+    }
 }
 if ($debug_flag)
 {
@@ -412,7 +430,7 @@ for ($cday = 1; $cday <= $days_in_month; $cday++)
     if ( $pview != 1 ) {
         echo "<div class=\"new_booking\">\n";
         if ($javascript_cursor)
-	    {
+        {
             echo "<SCRIPT language=\"JavaScript\">\n<!--\n";
             echo "BeginActiveCell();\n";
             echo "// -->\n</SCRIPT>";
diff --git a/blocks/mrbs/web/userweek.php b/blocks/mrbs/web/userweek.php
index 3b84108..e4e9509 100644
--- a/blocks/mrbs/web/userweek.php
+++ b/blocks/mrbs/web/userweek.php
@@ -143,13 +143,13 @@ if ( $pview != 1 ) {
 # This data will be retrieved day-by-day
 for ($j = 0; $j<=($num_of_days-1) ; $j++) {
 
-    $sql = "SELECT DISTINCT start_time, end_time, type, concat($tbl_entry.name,' Rm:',$tbl_room.room_name), $tbl_entry.id, $tbl_entry.description
-            FROM $tbl_entry
-                join $tbl_room on room_id=$tbl_room.id
-                left join {$CFG->prefix}course on $tbl_entry.name={$CFG->prefix}course.shortname
-                left join {$CFG->prefix}context on contextlevel=50 and instanceid={$CFG->prefix}course.id
-                left join {$CFG->prefix}role_assignments on contextid={$CFG->prefix}context.id and roleid=5
-            WHERE ({$CFG->prefix}role_assignments.userid=$TTUSER->id or $tbl_entry.create_by = '$TTUSER->username')
+    $booking_sql = "SELECT DISTINCT e.id AS id, start_time, end_time, type, concat(e.name,' Rm:',r.room_name) AS name, e.description
+            FROM ".$CFG->prefix."mrbs_entry AS e
+                JOIN ".$CFG->prefix."mrbs_room AS r ON e.room_id = r.id
+                LEFT JOIN {$CFG->prefix}course AS c ON e.name = c.shortname
+                LEFT JOIN {$CFG->prefix}context AS con ON contextlevel = 50 AND instanceid = c.id
+                LEFT JOIN {$CFG->prefix}role_assignments AS a ON contextid = con.id AND roleid=5
+            WHERE (a.userid=$TTUSER->id OR e.create_by = '$TTUSER->username')
             AND start_time <= $pm7[$j] AND end_time > $am7[$j]";
 
     # Each row returned from the query is a meeting. Build an array of the
@@ -161,13 +161,31 @@ for ($j = 0; $j<=($num_of_days-1) ; $j++) {
     # Note: weekday here is relative to the $weekstarts configuration variable.
     # If 0, then weekday=0 means Sunday. If 1, weekday=0 means Monday.
 
-    if ($debug_flag) echo "<br>DEBUG: query=$sql\n";
-    $res = sql_query($sql);
-    if (! $res) echo sql_error();
-    else for ($i = 0; ($row = sql_row($res, $i)); $i++)
-    {
+    if(!$bookings = get_records_sql($booking_sql)) {
+        $bookings = array();
+    }
+    $dst_booking_sql = "SELECT DISTINCT e.id AS id, start_time, end_time, type, concat(e.name,' Rm:',r.room_name) AS name, e.description, e.timestamp
+            FROM ".$CFG->prefix."mrbs_entry AS e
+                JOIN ".$CFG->prefix."mrbs_room AS r ON e.room_id = r.id
+                LEFT JOIN {$CFG->prefix}course AS c ON e.name = c.shortname
+                LEFT JOIN {$CFG->prefix}context AS con ON contextlevel = 50 AND instanceid = c.id
+                LEFT JOIN {$CFG->prefix}role_assignments AS a ON contextid = con.id AND roleid=5
+            WHERE (a.userid=$TTUSER->id OR e.create_by = '$TTUSER->username')
+            AND start_time <= ".mrbs_uncorrect_dst($pm7[$j])." AND end_time > ".mrbs_uncorrect_dst($am7[$j]);
+    if(!$dst_bookings = get_records_sql($dst_booking_sql)) {
+        $dst_bookings = array();
+    }
+    foreach ($dst_bookings as $key => $dst_booking) {
+        if($dst_booking->start_time != mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time)) {
+            $dst_booking->start_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time);
+            $dst_booking->end_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->end_time);
+            $bookings[$key] = $dst_booking;
+        }
+    }
+
+    foreach ($bookings as $booking)  {
         if ($debug_flag)
-            echo "<br>DEBUG: result $i, id $row[4], starts $row[0], ends $row[1]\n";
+            echo "<br>DEBUG: result $i, id $booking->id, starts $booking->start_time, ends $booking->end_time\n";
 
         # $d is a map of the screen that will be displayed
         # It looks like:
@@ -183,21 +201,21 @@ for ($j = 0; $j<=($num_of_days-1) ; $j++) {
         # Note: int casts on database rows for max may be needed for PHP3.
         # Adjust the starting and ending times so that bookings which don't
         # start or end at a recognized time still appear.
-        mrbs_correct_dst($row[1], $row[2]);
-        $start_t = max(round_t_down($row[0], $resolution, $am7[$j]), $am7[$j]);
-        $end_t = min(round_t_up($row[1], $resolution, $am7[$j]) - $resolution, $pm7[$j]);
+
+        $start_t = max(round_t_down($booking->start_time, $resolution, $am7[$j]), $am7[$j]);
+        $end_t = min(round_t_up($booking->end_time, $resolution, $am7[$j]) - $resolution, $pm7[$j]);
 
         for ($t = $start_t; $t <= $end_t; $t += $resolution)
         {
           //checks for double bookings
           if(empty($d[$j][date($format,$t)])){
-              $d[$j][date($format,$t)]["id"]    = $row[4];
-              $d[$j][date($format,$t)]["color"] = $row[2];
+              $d[$j][date($format,$t)]["id"]    = $booking->id;
+              $d[$j][date($format,$t)]["color"] = $booking->type;
               $d[$j][date($format,$t)]["data"]  .= "";
               $d[$j][date($format,$t)]["long_descr"]  .= "";
               $d[$j][date($format,$t)]["double_booked"]  = false;
           }else{
-              $d[$j][date($format,$t)]["id"]    .= ','.$row[4];
+              $d[$j][date($format,$t)]["id"]    .= ','.$booking->id;
               $d[$j][date($format,$t)]["data"]  .= "\n";
               $d[$j][date($format,$t)]["long_descr"]  .= ",";
               $d[$j][date($format,$t)]["double_booked"]  = true;
@@ -206,15 +224,15 @@ for ($j = 0; $j<=($num_of_days-1) ; $j++) {
 
         # Show the name of the booker in the first segment that the booking
         # happens in, or at the start of the day if it started before today.
-        if ($row[1] < $am7[$j])
+        if ($booking->end_time < $am7[$j])
         {
-            $d[$j][date($format,$am7[$j])]["data"] .= $row[3];
-            $d[$j][date($format,$am7[$j])]["long_descr"] .= $row[5];
+            $d[$j][date($format,$am7[$j])]["data"] .= $booking->name;
+            $d[$j][date($format,$am7[$j])]["long_descr"] .= $booking->description;
         }
         else
         {
-            $d[$j][date($format,$start_t)]["data"] .= $row[3];
-            $d[$j][date($format,$start_t)]["long_descr"] .= $row[5];
+            $d[$j][date($format,$start_t)]["data"] .= $booking->name;
+            $d[$j][date($format,$start_t)]["long_descr"] .= $booking->description;
         }
     }
 }
diff --git a/blocks/mrbs/web/week.php b/blocks/mrbs/web/week.php
index d24646f..1bd3bdd 100644
--- a/blocks/mrbs/web/week.php
+++ b/blocks/mrbs/web/week.php
@@ -201,7 +201,7 @@ if ( $pview != 1 ) {
 # This data will be retrieved day-by-day
 for ($j = 0; $j<=($num_of_days-1) ; $j++) {
 
-    $sql = "SELECT start_time, end_time, type, name, id, description
+    $booking_sql = "SELECT id,start_time, end_time, type, name,  description
             FROM $tbl_entry
             WHERE room_id = $room
             AND start_time <= $pm7[$j] AND end_time > $am7[$j]";
@@ -214,14 +214,30 @@ for ($j = 0; $j<=($num_of_days-1) ; $j++) {
     # should be labeled,  which is once for each meeting on each weekday.
     # Note: weekday here is relative to the $weekstarts configuration variable.
     # If 0, then weekday=0 means Sunday. If 1, weekday=0 means Monday.
-
     if ($debug_flag) echo "<br>DEBUG: query=$sql\n";
-    $res = sql_query($sql);
-    if (! $res) echo sql_error();
-    else for ($i = 0; ($row = sql_row($res, $i)); $i++)
-    {
+    if(!$bookings = get_records_sql($booking_sql)) {
+        $bookings = array();
+    }
+
+    $dst_booking_sql = "SELECT id,start_time, end_time, type, name, description, timestamp
+            FROM ".$CFG->prefix."mrbs_entry
+            WHERE room_id = $room
+            AND start_time <= ".mrbs_uncorrect_dst($pm7[$j])." AND end_time > ".mrbs_uncorrect_dst($am7[$j]);
+    if(!$dst_bookings = get_records_sql($dst_booking_sql)) {
+        $dst_bookings = array();
+    }
+    foreach ($dst_bookings as $key => $dst_booking) {
+        if($dst_booking->start_time != mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time)) {
+            $dst_booking->start_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->start_time);
+            $dst_booking->end_time = mrbs_correct_nodst($dst_booking->timestamp, $dst_booking->end_time);
+            $bookings[$key] = $dst_booking;
+        }
+    }
+
+    foreach ($bookings as $booking){
+
         if ($debug_flag)
-            echo "<br>DEBUG: result $i, id $row[4], starts $row[0], ends $row[1]\n";
+            echo "<br>DEBUG: result $i, id $booking->id, starts $booking->start_time, ends $booking->end_time\n";
 
         # $d is a map of the screen that will be displayed
         # It looks like:
@@ -238,28 +254,28 @@ for ($j = 0; $j<=($num_of_days-1) ; $j++) {
         # Adjust the starting and ending times so that bookings which don't
         # start or end at a recognized time still appear.
 
-        $start_t = max(round_t_down($row[0], $resolution, $am7[$j]), $am7[$j]);
-        $end_t = min(round_t_up($row[1], $resolution, $am7[$j]) - $resolution, $pm7[$j]);
+        $start_t = max(round_t_down($booking->start_time, $resolution, $am7[$j]), $am7[$j]);
+        $end_t = min(round_t_up($booking->end_time, $resolution, $am7[$j]) - $resolution, $pm7[$j]);
 
         for ($t = $start_t; $t <= $end_t; $t += $resolution)
         {
-            $d[$j][date($format,$t)]["id"]    = $row[4];
-            $d[$j][date($format,$t)]["color"] = $row[2];
+            $d[$j][date($format,$t)]["id"]    = $booking->id;
+            $d[$j][date($format,$t)]["color"] = $booking->type;
             $d[$j][date($format,$t)]["data"]  = "";
             $d[$j][date($format,$t)]["long_descr"]  = "";
         }
 
         # Show the name of the booker in the first segment that the booking
         # happens in, or at the start of the day if it started before today.
-        if ($row[1] < $am7[$j])
+        if ($booking->end_time < $am7[$j])
         {
-            $d[$j][date($format,$am7[$j])]["data"] = $row[3];
-            $d[$j][date($format,$am7[$j])]["long_descr"] = $row[5];
+            $d[$j][date($format,$am7[$j])]["data"] = $booking->name;
+            $d[$j][date($format,$am7[$j])]["long_descr"] = $booking->description;
         }
         else
         {
-            $d[$j][date($format,$start_t)]["data"] = $row[3];
-            $d[$j][date($format,$start_t)]["long_descr"] = $row[5];
+            $d[$j][date($format,$start_t)]["data"] = $booking->name;
+            $d[$j][date($format,$start_t)]["long_descr"] = $booking->description;
         }
     }
 }
